package com.wjy.util;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author ybxxszl
 * @date 2018年10月16日
 * @description Jackson工具类
 */
public class JacksonUtil {

    private static final ObjectMapper mapper = new ObjectMapper();

    public static ObjectMapper getObjectMapper() {
        return mapper;
    }

    /**
     * 将String转换成VO
     */
    public static <T> T toVO(String content, Class<T> valueType) {
        try {
            return mapper.readValue(content, valueType);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 将Object转换成String
     */
    public static String toString(Object value) {
        try {
            return mapper.writeValueAsString(value);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
